home *** CD-ROM | disk | FTP | other *** search
- Path: fc.hp.com!news
- From: Rick Wells <rwells>
- Newsgroups: comp.lang.c
- Subject: Re: Do you have ever pass structures?
- Date: 22 Feb 1996 16:23:13 GMT
- Organization: Hewlett-Packard Fort Collins Site
- Message-ID: <4gi59h$alk@fcnews.fc.hp.com>
- References: <4ge8mi$qjm@srvr1.engin.umich.edu> <312BE9C9.67A2284E@eden.com>
- NNTP-Posting-Host: blkbear.fc.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/715)
- X-URL: news:312BE9C9.67A2284E@eden.com
-
- > So is there any REAL advantage is passing an entire structure? Do people
- > ever do it? I've some people's source code and almost always, they
- > pass pointers to structures instead of the structure itself. In a way,
- > passing a pointer to an array instead of the array itself might be
- > feature not a bug in C. :)
-
- Yes. Not usually though. Small structures work fine:
-
- struct
- {
- unsigned char a;
- unsigned char b;
- } my_struct;
-
- my_function (my_struct);
-
- This may even be faster than passing a pointer. But if you are worried about
- speed to that degree at this point you should make your function a macro
- and compile it inline. My point is that for small structures it's a
- "don't care". For large structures you may care because it may take time and
- space to pass it by value.
-
- As mentioned in a previous reply the only advantage to passing structures
- by value is the avoidance of accidental modification of the caller's data.
- That's a real advantage in some cases.
-
- My opinion, Rick
-
-